/**
 * 进程交替运行
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{

    pid_t pid;

    pid = fork();
    if (0 == pid)
    { // 子进程
        int i = 0;
        for (; i < 10; ++i)
        {
            printf("I am child progress is id %d\n", getpid());
            sleep(1);
        }
    }
    else if (0 < pid)
    { // 父进程
        int i = 0;
        for (; i < 10; ++i)
        {
            printf("I am parent progress is id %d\n", getpid());
            sleep(1);
        }
    }
    else
    {
        perror("fork error : ");
        exit(EXIT_FAILURE);
    }

    return 0;
}